package com.clps.designPatterns.chapter02.线程安全问题;

public class Singleton03 {
    /**
     * 使用静态变量
     */

    private  static  volatile  Singleton03 singleton03 = null;

    public Singleton03() {
    }

    public  static  Singleton03 getInstance(){
        //如果实例不存在,则同步
        if(singleton03 == null){
            //只有第一次才会彻底执行这里的代码
            synchronized (Singleton03.class){
                if(singleton03 == null){
                    singleton03 = new Singleton03();
                }
            }
        }
        return  singleton03;
    }
}
